﻿/* Write a program that reads a text file and inserts line numbers in front of each of its lines. The result should be written to another text file.*/
using System;
using System.IO;
using System.Text;

namespace _3.InsertLineNumbers
{
    class InsertLineNumbers
    {
        static void Main()
        {
            Console.Write("Path to file (along with the filename): ");
            string path_to_file = Console.ReadLine();
            
            StreamReader SR = new StreamReader(@path_to_file);
            string line = SR.ReadLine();
            int countLines = 0;
            StringBuilder res = new StringBuilder();
            try
            {
                using (SR)
                {
                    while (line != null)
                    {
                        countLines++;
                        //res.Append(countLines);
                        //res.Append(":");
                        string newlinestr = string.Format("#{0}:{1}\r\n", countLines, line);
                        res.Append(newlinestr);
                        line = SR.ReadLine();

                        Console.WriteLine(newlinestr);
                    }
                }
            }
            catch (IOException e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            
            Console.Write("Path to output file (along with the filename): ");
            string path_to_output_file = Console.ReadLine();

            StreamWriter SW = new StreamWriter(@path_to_output_file, false, Encoding.GetEncoding("UTF-8"));
            using (SW)
            {
                SW.Write(res);
            }
            Console.WriteLine("Data succesfully written to " + path_to_output_file);
        }
    }
}
